﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuanLyChungCu_V.BussinessTỉer
{
    class ServiceManagerService
    {
        
        SQLConnection sql_conn;
        public ServiceManagerService()
        {
            try
            {
                sql_conn = new SQLConnection(null); // Lay ConnectionString trong DataConnection.xml, neu file khong ton tai thi tao moi va ghi lai ConnectionString
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
        


      
        public void AddService(string name, int giatien)
        {
            QLCCDataContext ctx = new QLCCDataContext();
            ctx.Connection.ConnectionString = sql_conn.ConnectionString;
            ctx.DichVus.InsertOnSubmit(new DichVu
            {
                TenDV= name,
                GiaTien = giatien,
                DonVi = " ",
            });
            ctx.SubmitChanges();
        }
       
        
        public IList<ServiceDTO> FindService(string name)

        {
            QLCCDataContext ctx = new QLCCDataContext();
            ctx.Connection.ConnectionString = sql_conn.ConnectionString;

            var service = from p in ctx.DichVus

                         where p.TenDV.Contains(name)
                         select new ServiceDTO
                         {
                             id = p.idDichVu,
                             name = p.TenDV,
                             price = (int)p.GiaTien,
                             donvi = p.DonVi,
                            
                         };
            return service.ToList<ServiceDTO>();

        }
    }
}
